import { defineStore } from "pinia";

export const useMainStore = defineStore("mainStore", {
    state: () => {
        return {
            keyIsWhat : "ageageage",
            ifPassed: false,
            searchWhat: "",
            keyValue: [
                "age",
                "jdm",
                "mali3"
            ],
            urlRulesNoSuffix: [
                {
                    urlPrePart: [
                        "https://www.",
                        "mys.com/search?query="
                    ],
                    urlSufPart: ""
                },
                {
                    urlPrePart : [
                        "https://www.ys",
                        ".net/index.php/vod/search.html?wd="
                    ],
                    urlSufPart : "&submit="
                },
                {
                    urlPrePart : [
                        "https://www.mali",
                        ".com/vodsearch/-------------.html?wd="
                    ],
                    urlSufPart : ""
                }
            ]
        }
    },
    getters: {
        checkIfPassed(state) {
            return state.ifPassed;
        },
        getWholeFromPreUrl(state) {
            let urlArrs = [];

            for (let index = 0; index < state.keyValue.length; index++) {
                if (state.urlRulesNoSuffix[index].urlSufPart == "") {
                    urlArrs.push(state.urlRulesNoSuffix[index].urlPrePart[0] + state.keyValue[index] + state.urlRulesNoSuffix[index].urlPrePart[1] + state.valueTransFromPreUrl(index, state.searchWhat));
                } else {
                    urlArrs.push(state.urlRulesNoSuffix[index].urlPrePart[0] + state.keyValue[index] + state.urlRulesNoSuffix[index].urlPrePart[1] + state.valueTransFromPreUrl(index, state.searchWhat) + state.urlRulesNoSuffix[index].urlSufPart);
                }
            }

            return urlArrs;
        }
    },
    actions: {
        isPassed(newKey) {
            if (newKey == this.keyIsWhat) {
                this.ifPassed = true;

                return true;
            } else {
                this.ifPassed = false;

                return false;
            }
        },
        changeSearchWhat(newStr) {
            this.searchWhat = newStr;
        },
        valueTransFromPreUrl(index, value) {
            switch (index) {
                case 0:
                    return value;
                case 1:
                    return value;
                case 2:
                    return value;
            }
        }
    }
})